package com.xtayfjpk.security.sasl;

import java.io.IOException;
import java.security.Provider;
import java.security.Security;
import java.util.Map;

import javax.security.auth.callback.Callback;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.callback.UnsupportedCallbackException;
import javax.security.sasl.Sasl;
import javax.security.sasl.SaslClient;
import javax.security.sasl.SaslServer;

public class Test {
	
	public static void main(String[] args) throws Exception {
		String mechFilter = "SaslServerFactory.DIGEST-MD5";
        Provider[] provs = Security.getProviders(mechFilter);
        
        System.out.println(provs.length);
		
		String[] mechanisms = new String[]{"DIGEST-MD5", "PLAIN"};
		String authorizationId = null;
		String protocol = "ldap";
		String serverName = "127.0.0.1";
		Map<String, ?> props = null;
		CallbackHandler cbh = new CallbackHandler() {
			
			@Override
			public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
				System.out.println("xxxxxxx");
			}
		};
		SaslClient client = Sasl.createSaslClient(mechanisms, authorizationId, protocol, serverName, props, cbh);
		System.out.println(client.hasInitialResponse());
		
		
	
		String mechanism = "DIGEST-MD5";
		SaslServer server = Sasl.createSaslServer(mechanism, protocol, serverName, props, cbh);
		System.out.println(server);
		
		byte[] data = "xtayfjpk".getBytes();
		server.wrap(data, 0, data.length);
		
		
		
		//client.wrap(data, 0, data.length);
	}
}
